package com.sgxy.wmservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sgxy.commonutils.R;
import com.sgxy.wmservice.entity.WmInputOrder;
import com.sgxy.wmservice.entity.WmOutputOrder;
import com.sgxy.wmservice.entity.vo.InputOrderVo;
import com.sgxy.wmservice.entity.vo.OutputOrderVo;
import com.sgxy.wmservice.service.WmInputOrderService;
import com.sgxy.wmservice.service.WmOutputOrderService;
import com.sgxy.wmservice.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/wmservice/wminputorder")
public class WmInputOrderController {
    @Autowired
    private WmInputOrderService wmInputOrderService;
    @PostMapping("{page}/{limit}")
    public R index(@PathVariable Long page,
                   @PathVariable Long limit,
                   @RequestBody(required = false) WmInputOrder wmInputOrder){
        Page<InputOrderVo> InputOrderPage = new Page<>(page,limit);

        wmInputOrderService.selectPageVoList(InputOrderPage, wmInputOrder);

        return R.ok().data("items",InputOrderPage.getRecords()).data("total",InputOrderPage.getTotal());
    }

    @GetMapping("getInputOrderById/{id}")
    public R getInputOrderById(@PathVariable String id){
        InputOrderVo InputOrderVo = wmInputOrderService.selectOneById(id);
        return R.ok().data("InputOrderVo",InputOrderVo);
    }
    @PostMapping("addInputOrder")
    public R addInputOrder(@RequestBody WmInputOrder wmInputOrder){
        wmInputOrder.setInputNo(OrderNoUtil.getOrderNo());
        wmInputOrderService.addInputOrder(wmInputOrder);
        return R.ok();
    }
    @PostMapping("updateInputOrder")
    public R updateInputOrder(@RequestBody WmInputOrder wmInputOrder){
        wmInputOrderService.updateInputOrder(wmInputOrder);
        return R.ok();
    }
    //删除
    @DeleteMapping("{id}")
    public R deleteOrders(@PathVariable String id){
        wmInputOrderService.deleteById(id);
        return R.ok();
    }
}

